<?php
/**
 * Class Template
 *
 * Project: LanguageTranslation<br/>
 * File: Template.php
 * 
 */

/**
 * Class Template
 *
 * Provides the functionality to work with HTML templates.
 *
 */
class Template {

	/**
	 * @var array Assigned variables
	 * @access private
	 */
	var $_aVars;

	/**
	 * Constructor
	 * 
	 * @access public
	 */
	function Template() {
		$this->_aVars = array();
	}

	/**
	 * Assign variables
	 * 
	 * Assigns varibles to current template. This takes name and value or
	 * an associative array of variables as a parameters.
	 * 
	 * @access public
	 */
	function assign() {
		$aParams = func_get_args();
		if (count($aParams) > 1) {
			for ($i = 0; $i < count($aParams); $i += 2) {
				$this->_aVars[$aParams[$i]] =& $aParams[$i + 1];
			}
		}
		elseif (count($aParams) == 1) {
			$aVarNames = array_keys($aParams[0]);
			for ($i = 0; $i < count($aVarNames); $i++) {
				$this->_aVars[$aVarNames[$i]] =& $aParams[0][$aVarNames[$i]];
			}
		}
	}

	/**
	 * Assign variable by reference
	 * 
	 * Assigns varibles to current template by reference.
	 * 
	 * @access public
	 * 
	 * @param string $sName Name of variable
	 * @param variant $vValue Value of variable
	 */
	function assignByRef($sName, &$vValue) {
		$this->_aVars[$sName] =& $vValue;
	}

	/**
	 * Displays the page
	 * 
	 * Loads a template from a file and runs it.
	 * 
	 * @access public
	 * 
	 * @param string $sFileName Name of a template file
	 */
	function display($sFileName) {
		extract($this->_aVars, EXTR_REFS);
		include $sFileName;
	}
}
?>